package com.company;

import java.util.Scanner;

/**
 * @author zhangjian
 * @data 2023/3/19
 * @Version 1.0
 * @Descripion
 */
public class 最大子矩阵之和 {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int row = sc.nextInt();
        int lie = sc.nextInt();
        int[][] array = new int[row][lie];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < lie; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        System.out.println(maxSubMatrix(lie, array));
    }

    private static int maxSubMatrix(int n, int[][] array) {
        int max = 0, sum = Integer.MIN_VALUE;
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            for (int k = 0; k < n; k++)// 初始化b[]
            {
                b[k] = 0;
            }
            for (int j = i; j < n; j++)// 把第i行到第j行相加,对每一次相加求出最大值
            {
                for (int k = 0; k < n; k++) {
                    b[k] += array[j][k];
                }
                max = maxSubArray(b);
                sum = Math.max(max, sum);
            }
        }
        return sum;
    }

    // 求子段的最大和
    private static int maxSubArray(int a[]) {
        int temp = 0;
        int sum = Integer.MIN_VALUE;
        for (int i = 0; i < a.length; i++) {
            temp += a[i];
            if (temp > 0) {
                sum = Math.max(sum, temp);
            }
        }
        return sum;
    }

}
/***
 * 4 4 0 -2 -7 0 9 2 -6 2 -4 1 -4 1 -1 8 0 -2
 **/
